package org.springblade.modules.mes.opcua.vo;

import org.springblade.core.tool.utils.StringUtil;

public class OpcUaVO {

	private Object value;

	private String preKey;

	private String siteCode;

	private String actKey;

	private String position;


	public OpcUaVO(String inKey, Object value) {
		int lastIdx = StringUtil.lastIndexOfIgnoreCase(inKey, ".");
		this.preKey = inKey.substring(0, lastIdx);
		this.value = value;
		String[] keys = inKey.split("\\.");
		this.siteCode = keys[1];
		String opcuaKey = keys[2];
		actKey = opcuaKey;
		//默认
		this.position = "0";
		int requestPositionIdx = opcuaKey.indexOf("_");
		if (requestPositionIdx > 0) {
			position = opcuaKey.substring(requestPositionIdx + 1);
			actKey = opcuaKey.substring(0, requestPositionIdx);
			if (position.length() == 0) {
				position = "0";
			}
		}
	}

	public Object getValue() {
		return value;
	}

	public String getSiteCode() {
		return siteCode;
	}

	public String getPosition() {
		return position;
	}

	public String getActKey() {
		return actKey;
	}

	public String opcuaKey(String key, String position) {
		StringBuilder res = new StringBuilder();
		res.append(preKey).append(".").append(key);
		if (position != null && !"0".equals(position) && position.length() > 0) {
			res.append("_").append(position);
		}
		return res.toString();
	}
}
